package com.reids.ch01.controller;

import com.reids.ch01.bean.Address;
import com.reids.ch01.bean.Student;
import com.reids.ch01.service.RedisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/***
 *
 * 测试redis
 * @author wind
 * @since 2020-06-22
 */
@Slf4j
@RestController
@RequestMapping("/redis")
public class RedisController {

    @Autowired
    private RedisService redisService;

    @RequestMapping("/testString")
    public String testString(String key,String value) {
        log.debug("testString--------key={}-------value={}------",key,value);
        redisService.set(key,value);
        return "OK";
    }

    @RequestMapping("/testStringForObject")
    public String testStringForObject(String city,String country){
        log.debug("testString--------city={}-------country={}------",city,country);
        redisService.set("user",new Address(city,country));
        return "OK";
    }

    @RequestMapping("/testList")
    public String testList(int age,String name) {
        log.debug("testList--------age={}-------name={}------",age,name);
        redisService.listRightPush("student",new Student(age,name));
        return "OK";
    }

    @RequestMapping("/testGetList")
    public String testGetList(String key) {
        log.debug("testGetList--------key={}-------",key);
        redisService.getListBean(key,Student.class);
        return "OK";
    }

    @RequestMapping("/publishMsg")
    public String testPublishMsg(String content) {
        log.debug("publishMsg req content:{}",content);
        redisService.publish("pmp",content);
        return "OK";
    }
}
